(function(_,$){
	_.Html.window = "<div class='jdmer_window'>" +
	"<div class='jdmer_window_shadow_width'></div>"+
	"	<div class='win_shadow'>"+
	"		<div class='win_top'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"		<div class='win_middle'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"		<div class='win_bottom'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"	</div>"+
	"	<div class='win_border'>"+
	"		<div class='win_top'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"		<div class='win_middle'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"		<div class='win_bottom'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"	</div>"+
	"	<div class='win_container'>"+
	"		<div class='win_top'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'>" +
	"				<div class='win_title'></div>"+
	"				<div class='win_buttons'>"+
	"					<div class='close'></div>"+
	"					<div class='re'></div>"+
	"					<div class='max'></div>"+
	"					<div class='min'></div>"+
	"				</div>"+
	"				<div class='win_buttons_inductor'>"+
	"					<div class='close'></div>"+
	"					<div class='re'></div>"+
	"					<div class='max'></div>"+
	"					<div class='min'></div>"+
	"				</div>"+
	"			</div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"		<div class='win_middle'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_content'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"		<div class='win_bottom'>"+
	"			<div class='win_left'></div>"+
	"			<div class='win_center'></div>"+
	"			<div class='win_right'></div>"+
	"		</div>"+
	"	</div>"+
	"</div>";
	
	/**
	 * Window对象
	 */
	var Window = function(_config){
		var _this = this;	//全局引用
		this.uid = _.Util.guid();	//唯一编号
		var config = {	//配置参数
			id : null,
			container : "body",
			width : 600,
			height : 400,
			top : 0,
			left : 0,
			minHeight : 70,
			minWidth : 180,
			url : null,	//加载的地址
			title : "无标题窗口",
			iframe : false,
			max : false,
			zindex : 0,
			onDisplay : null,	//显示时回调
			onDestroy : null,	//销毁时回调
			onTitleChange : null,	//标题发生变化时回调
			onToTop : null,
			onMin : null,
			onMax : null,
			onRe : null,
			draggable : true,
			resizable : true,
			maxable : true,	//是否可以最大化
			minable : true,	//是否可以最小化
			closeable : true,	//是否可以关闭
			mask : false
		};
		var mined = false;
		var maxed = false;
		var originalSize = {	//窗口的原始尺寸
			height : 0,
			width : 0,
			top : 0,
			left : 0
		};
		$.extend(config,_config);	//合并用户的配置参数
		this.jQuery = null;
		var jq = {	//jQuery对象
			obj : null,
			shadow : null,
			ctn_top : null,
			sd_top_l : null,
			sd_top_c : null,
			sd_top_r : null,
			sd_mid : null,
			sd_mid_l : null,
			sd_mid_c : null,
			sd_mid_r : null,
			sd_btm : null,
			sd_btm_l : null,
			sd_btm_c : null,
			sd_btm_r : null,
			
			border : null,
			bd_top : null,
			bd_top_l : null,
			bd_top_c : null,
			bd_top_r : null,
			bd_mid : null,
			bd_mid_l : null,
			bd_mid_c : null,
			bd_mid_r : null,
			bd_btm : null,
			bd_btm_l : null,
			bd_btm_c : null,
			bd_btm_r : null,
			
			container : null,
			ctn_top : null,
			ctn_top_l : null,
			ctn_top_c : null,
			ctn_top_r : null,
			ctn_mid : null,
			ctn_mid_l : null,
			ctn_mid_c : null,
			ctn_mid_r : null,
			ctn_btm : null,
			ctn_btm_l : null,
			ctn_btm_c : null,
			ctn_btm_r : null,
			
			btns : null,
			btnsi : null,
			btn_close : null,
			btn_max : null,
			btn_re : null,
			btn_min : null,
			btn_iclose : null,
			btn_imax : null,
			btn_ire : null,
			btn_imin : null,
			
			shadow_width:null,
			title : null
		};
		var htmlBase = _.Html.window;	//html原型
		
		/**
		 * 显示在Window所属的容器内
		 */
		this.display = function(){
			if(mined){
				_this.re();
				return this;
			}
			if(jq.obj){
				return this;
			}
			initjQuery();
			jq.obj.attr("jdmer_uid",_this.uid);
			jq.obj.hide();
			initButtonEvent();
			initDraggable();
			initResizable();
			_this.id(config.id);
			_this.draggable(config.draggable);
			_this.resizable(config.resizable);
			_this.maxable(config.maxable);
			_this.minable(config.minable);
			_this.closeable(config.closeable);
			_this.container(config.container);
			_this.width(config.width);
			_this.height(config.height);
			_this.top(config.top);
			_this.left(config.left);
			_this.title(config.title);
			_this.mask(config.mask);
			jq.obj.data("jDreamerObject",_this);
			
			if(config.max){
				_this.max();
			}
			if(config.onDisplay){
				config.onDisplay(_this);
			}
			//进入屏幕
			
			jq.obj.css("left", - config.width).show().animate({
				left : config.left + 100
			},function(){
				jq.obj.animate({
					left : config.left
				},function(){
					_this.iframe(config.iframe);
					_this.toTop();
				});
			});
			return this;
		};
		
		/**
		 * 是否是模态窗口
		 */
		this.mask = function(_mask){
			if(_mask == undefined){
				return config.mask;
			}else{
				config.mask = _mask;
				if(jq.obj){
					if(config.mask){
						_this.minable(false);
						var maskDiv = $("#mask_"+_this.uid);
						if(maskDiv.size() == 0){
							maskDiv = $("<div class='jdmer_window_mask' id='mask_"+_this.uid+"'></div>");
						}
						maskDiv.insertBefore(jq.obj);
						maskDiv.css("z-index",jq.obj.css("z-index"));
						maskDiv.show();
					}else{
						_this.minable(config.minable);
						var maskDiv = $("#mask_"+_this.uid);
						maskDiv.hide();
					}
				}
				return this;
			}
		};
		
		/**
		 * 设置id属性
		 */
		this.id = function(_id){
			if(_id == undefined){
				return config.id;
			}else{
				config.id = _id;
				if(jq.obj && config.id){
					jq.obj.attr("id",config.id);
				}
				return this;
			}
		};
		
		this.maxable = function(_maxable){
			if(_maxable == undefined){
				return config.maxable;
			}else{
				config.maxable = _maxable;
				if(jq.obj){
					if(config.maxable){
						jq.btn_max.removeClass("max_disabled");
					}else{
						jq.btn_max.addClass("max_disabled");
					}
				}
				return this;
			}
		};
		
		this.minable = function(_minable){
			if(_minable == undefined){
				return config.minable;
			}else{
				config.minable = _minable;
				if(jq.obj){
					if(config.minable){
						jq.btn_min.removeClass("min_disabled");
					}else{
						jq.btn_min.addClass("min_disabled");
					}
				}
				return this;
			}
		};
		
		this.closeable = function(_closeable){
			if(_closeable == undefined){
				return config.closeable;
			}else{
				config.closeable = _closeable;
				if(jq.obj){
					if(config.closeable){
						jq.btn_close.removeClass("close_disabled");
					}else{
						jq.btn_close.addClass("close_disabled");
					}
				}
				return this;
			}
		};
		
		/**
		 * 是否可以拖动
		 */
		this.draggable = function(_draggable){
			if(_draggable == undefined){
				return config.draggable;
			}else{
				config.draggable = _draggable;
				if(jq.obj){
					if(config.draggable){
						jq.obj.draggable( "option", "disabled", false );
					}else{
						jq.obj.draggable( "option", "disabled", true );
					}
				}
				return this;
			}
		};
		
		/**
		 * 是否可以重置大小
		 */
		this.resizable = function(_resizable){
			if(_resizable == undefined){
				return config.resizable;
			}else{
				config.resizable = _resizable;
				if(jq.obj){
					if(config.resizable){
						jq.obj.resizable( "option", "disabled", false );
					}else{
						jq.obj.resizable( "option", "disabled", true );
					}
				}
				return this;
			}
		};
		
		/**
		 * 设置z轴的值
		 * @param _zindex	z的值
		 */
		this.zindex = function(_zindex){
			if(_zindex == undefined){
				return config.zindex;
			}else{
				config.zindex = _zindex;
				if(jq.obj){
					var maskDiv = $("#mask_"+_this.uid);
					maskDiv.css("z-index",config.zindex);
					jq.obj.css("z-index",config.zindex)
					.attr("jdmer_win_zindex",config.zindex);
				}
				return this;
			}
		};
		
		/**
		 * 是否启用iframe框架
		 */
		this.iframe = function(_iframe){
			if(_iframe == undefined){
				return config.iframe;
			}else{
				config.iframe = _iframe;
				if(jq.obj){
					if(config.iframe){
						jq.ctn_mid_c.html("<iframe width='100%' height='100%' frameborder='0'></iframe>");
					}else{
						jq.ctn_mid_c.html("");
					}
					_this.url(config.url);
				}
				return this;
			}
		};
		
		/**
		 * 设置容器
		 * @param _container	容器
		 */
		this.container = function(_container){
			if(_container == undefined){
				return $(config.container);
			}else{
				config.container = _container;
				if(jq.obj){
					jq.obj.appendTo($(config.container));
				}
				return this;
			}
		};
		
		/**
		 * 销毁当前对象
		 */
		this.destroy = function(){
			if(jq.obj && !jq.btn_close.hasClass("close_disabled")){
				var ctn = _this.container();
				var left = _this.left();
				jq.obj.animate({
					left :  left - 100
				},function(){
					jq.obj.animate({
						left : ctn.width()
					},function(){
						var allOnremove = jq.obj.find("*[onremove]");
						allOnremove.each(function(i){
							var onremove = allOnremove.eq(i);
							try{
								eval(onremove.attr("onremove"));	//执行事件
							}catch(e){}
						});
						
						if(config.onDestroy){
							config.onDestroy(_this);
						}
						var maskDiv = $("#mask_"+_this.uid);
						maskDiv.remove();
						try{jq.ctn_mid_c.find("iframe").attr("src","");}catch(e){}
						jq.obj.remove();
						clearjQuery();
						_this = undefined;
						delete _this;
					});
				});
			}
		};
		
		/**
		 * 是否最大化
		 */
		this.isMaxed = function(){
			return maxed;
		};
		
		/**
		 * 是否最小化
		 */
		this.isMined = function(){
			return mined;
		};
		
		/**
		 * 在容器内置顶
		 */
		this.toTop = function(){
			if(_this.isTop()){	//如果已经是最高的
				return _this;
			}
			var topWin = _.Window.getTop(_this.container());
			var z = 10;
			if(topWin){	//如果存在
				topWin.jQuery.removeAttr("ontop");	//移除原属性
				z = Number(topWin.jQuery.attr("jdmer_win_zindex")) + 1;
			}
			if(jq.obj){
				jq.obj.attr("ontop","true");
			}
			if(config.onToTop){
				config.onToTop(_this);
			}
			_this.zindex(z);
			return _this;
		};
		
		/**
		 * 判断是否是最高
		 */
		this.isTop = function(){
			if(jq.obj){
				var is = jq.obj.attr("ontop");
				if(is == "true"){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		};
		
		this.max = function(){
			if(jq.obj && !maxed && !jq.btn_max.hasClass("max_disabled")){
				var ctn = $(config.container);
				var width = ctn.width();
				var height = ctn.height();
				
				originalSize.height = _this.height();
				originalSize.width = _this.width();
				originalSize.top = _this.top();
				originalSize.left = _this.left();
				
				_this.height(height);
				_this.width(width);
				_this.left(0);
				_this.top(0);
				jq.obj.draggable( "option", "disabled", true );
				jq.obj.resizable( "option", "disabled", true );
				
				jq.btn_imax.hide();
				jq.btn_max.hide();
				jq.btn_re.show();
				jq.btn_ire.show();
				maxed = true;
			}
			if(config.onMax){
				config.onMax(_this);
			}
			return this;
		};
		
		this.re = function(){
			if(!jq.obj){
				return this;
			}
			if(mined){
				jq.obj.show();
				mined = false;
			}else if(maxed){
				_this.height(originalSize.height);
				_this.width(originalSize.width);
				_this.left(originalSize.left);
				_this.top(originalSize.top);
				jq.obj.draggable( "option", "disabled", false );
				jq.obj.resizable( "option", "disabled", false );
				jq.btn_imax.show();
				jq.btn_max.show();
				jq.btn_re.hide();
				jq.btn_ire.hide();
				maxed = false;
			}
			if(config.onRe){
				config.onRe(_this);
			}
			return this;
		};
		
		/**
		 * 最小化
		 */
		this.min = function(){
			if(jq.obj && !jq.btn_min.hasClass("min_disabled")){
				jq.obj.hide();
				mined = true;
			}
			if(config.onMin){
				config.onMin(_this);
			}
		};
		
		this.top = function(_top){
			if(_top == undefined){
				if(jq.obj){
					return jq.obj.get(0).offsetTop;
				}
				return config.top;
			}else{
				if(_top < 0){
					_top = 0;
				}
				config.top = _top;
				if(jq.obj){
					jq.obj.css("top",config.top);
				}
				return this;
			}
		};
		
		this.left = function(_left){
			if(_left == undefined){
				if(jq.obj){
					return jq.obj.get(0).offsetLeft;
				}
				return config.left;
			}else{
				if(_left < 0){
					_left = 0;
				}
				config.left = _left;
				if(jq.obj){
					jq.obj.css("left",config.left);
				}
				return this;
			}
		};
		
		/**
		 * 设置标题
		 * @param _title	标题
		 */
		this.title = function(_title){
			if(_title == undefined){
				return config.title;
			}else{
				config.title = _title;
				if(config.onTitleChange){
					config.onTitleChange(_this);
				}
				if(jq.title){
					jq.title.html(config.title);
				}
				return this;
			}
		};
		
		/**
		 * 加载某地址
		 * @param _url	要加载的地址
		 */
		this.url = function(_url){
			if(_url == undefined){
				return config.url;
			}else{
				config.url = _url;
				if(jq.obj){
					if(config.iframe){
						jq.ctn_mid_c.children("iframe").attr("src",config.url);
					}else{
						jq.ctn_mid_c.loader({
							url : config.url,
							callback : function(){
								_.Changer(jq.obj);
							}
						});
					}
				}
			}
			return this;
		};
		
		/**
		 * 设置宽度
		 * @param _width	宽度值
		 */
		this.width = function(_width){
			if(_width == undefined){
				if(jq.obj){
					return jq.obj.width();
				}
				return config.width;
			}else{
				config.width = _width;
				if(!jq.obj){
					return this;
				}
				jq.obj.width(config.width);
				var shadowWidth = jq.shadow_width.width();
				var sdW = config.width + shadowWidth * 2;
				jq.shadow.width(sdW);
				jq.sd_top_c.width(sdW - jq.sd_top_l.width() - jq.sd_top_r.width());
				jq.sd_mid_c.width(sdW - jq.sd_mid_l.width() - jq.sd_mid_r.width());
				jq.sd_btm_c.width(sdW - jq.sd_btm_l.width() - jq.sd_btm_r.width());
				
				jq.border.width(config.width);
				jq.bd_top_c.width(config.width - jq.bd_top_l.width() - jq.bd_top_r.width());
				jq.bd_mid_c.width(config.width - jq.bd_mid_l.width() - jq.bd_mid_r.width());
				jq.bd_btm_c.width(config.width - jq.bd_btm_l.width() - jq.bd_btm_r.width());
				
				jq.container.width(config.width);
				jq.ctn_top_c.width(config.width - jq.ctn_top_l.width() - jq.ctn_top_r.width());
				jq.ctn_mid_c.width(config.width - jq.ctn_mid_l.width() - jq.ctn_mid_r.width());
				jq.ctn_btm_c.width(config.width - jq.ctn_btm_l.width() - jq.ctn_btm_r.width());
				jq.title.width(jq.ctn_top_c.width() - jq.btns.width());
				
				jq.obj.find("div[changer='borderLayout']").eq(0).borderLayout({
					selector : "div[changer='borderLayout']"
				});
				
				return this;
			}
		};
		
		/**
		 * 设置高度
		 * @param _height	高度值
		 */
		this.height = function(_height){
			if(_height == undefined){
				if(jq.obj){
					return jq.obj.height();
				}
				return config.height;
			}else{
				config.height = _height;
				if(!jq.obj){
					return this;
				}
				jq.obj.height(config.height);
				var shadowWidth = jq.shadow_width.width();
				var sdH = config.height + shadowWidth * 2;
				jq.shadow.height(sdH);
				var sdmH = sdH - jq.sd_top.height() - jq.sd_btm.height();
				jq.sd_mid.height(sdmH);
				jq.sd_mid_l.height(sdmH);
				jq.sd_mid_c.height(sdmH);
				jq.sd_mid_r.height(sdmH);
				
				var bdmH = config.height - jq.bd_top.height() - jq.bd_btm.height();
				jq.border.height(config.height);
				jq.bd_mid.height(bdmH);
				jq.bd_mid_l.height(bdmH);
				jq.bd_mid_c.height(bdmH);
				jq.bd_mid_r.height(bdmH);
				
				var ctnmH = config.height - jq.ctn_top.height() - jq.ctn_btm.height();
				jq.container.height(config.height);
				jq.ctn_mid.height(ctnmH);
				jq.ctn_mid_l.height(ctnmH);
				jq.ctn_mid_c.height(ctnmH);
				jq.ctn_mid_r.height(ctnmH);
				
				jq.obj.find("div[changer='borderLayout']").eq(0).borderLayout({
					selector : "div[changer='borderLayout']"
				});
				
				return this;
			}
		};
		
		/**
		 * 初始化jQuery对象
		 */
		var initjQuery = function(){
			if(jq.obj == null){
				jq.obj = $(htmlBase);
				_this.jQuery = jq.obj;
				jq.shadow = jq.obj.children(".win_shadow");
				jq.sd_top = jq.shadow.children(".win_top");
				jq.sd_top_l = jq.sd_top.children(".win_left");
				jq.sd_top_c = jq.sd_top.children(".win_center");
				jq.sd_top_r = jq.sd_top.children(".win_right");
				
				jq.sd_mid = jq.shadow.children(".win_middle");
				jq.sd_mid_l = jq.sd_mid.children(".win_left");
				jq.sd_mid_c = jq.sd_mid.children(".win_center");
				jq.sd_mid_r = jq.sd_mid.children(".win_right");
				
				jq.sd_btm = jq.shadow.children(".win_bottom");
				jq.sd_btm_l = jq.sd_btm.children(".win_left");
				jq.sd_btm_c = jq.sd_btm.children(".win_center");
				jq.sd_btm_r = jq.sd_btm.children(".win_right");
				
				jq.border = jq.obj.children(".win_border");
				jq.bd_top = jq.border.children(".win_top");
				jq.bd_top_l = jq.bd_top.children(".win_left");
				jq.bd_top_c = jq.bd_top.children(".win_center");
				jq.bd_top_r = jq.bd_top.children(".win_right");
				
				jq.bd_mid = jq.border.children(".win_middle");
				jq.bd_mid_l = jq.bd_mid.children(".win_left");
				jq.bd_mid_c = jq.bd_mid.children(".win_center");
				jq.bd_mid_r = jq.bd_mid.children(".win_right");
				
				jq.bd_btm = jq.border.children(".win_bottom");
				jq.bd_btm_l = jq.bd_btm.children(".win_left");
				jq.bd_btm_c = jq.bd_btm.children(".win_center");
				jq.bd_btm_r = jq.bd_btm.children(".win_right");
				
				jq.container = jq.obj.children(".win_container");
				jq.ctn_top = jq.container.children(".win_top");
				jq.ctn_top_l = jq.ctn_top.children(".win_left");
				jq.ctn_top_c = jq.ctn_top.children(".win_center");
				jq.ctn_top_r = jq.ctn_top.children(".win_right");
				
				jq.ctn_mid = jq.container.children(".win_middle");
				jq.ctn_mid_l = jq.ctn_mid.children(".win_left");
				jq.ctn_mid_c = jq.ctn_mid.children(".win_content");
				jq.ctn_mid_r = jq.ctn_mid.children(".win_right");
				
				jq.ctn_btm = jq.container.children(".win_bottom");
				jq.ctn_btm_l = jq.ctn_btm.children(".win_left");
				jq.ctn_btm_c = jq.ctn_btm.children(".win_center");
				jq.ctn_btm_r = jq.ctn_btm.children(".win_right");
				
				jq.btns = jq.ctn_top_c.children(".win_buttons");
				jq.btn_close = jq.btns.children(".close");
				jq.btn_max = jq.btns.children(".max");
				jq.btn_re = jq.btns.children(".re");
				jq.btn_min = jq.btns.children(".min");
				jq.btnsi = jq.ctn_top_c.children(".win_buttons_inductor");
				jq.btn_iclose = jq.btnsi.children(".close");
				jq.btn_imax = jq.btnsi.children(".max");
				jq.btn_ire = jq.btnsi.children(".re");
				jq.btn_imin = jq.btnsi.children(".min");
				
				jq.shadow_width = jq.obj.children(".jdmer_window_shadow_width");
				jq.title = jq.ctn_top_c.children(".win_title");
				
				jq.obj.appendTo($(config.container));
				
				//鼠标离开窗口触发事件，将body的鼠标样式改变。
				jq.obj.unbind("mouseout").mouseout(function(){
					$("body").css("cursor","default");
				});
				jq.obj.click(function(){
					_this.toTop();
				});
				jq.title.dblclick(function(){
					if(maxed){
						_this.re();
					}else{
						_this.max();
					}
				});
			}
		};
		
		var clearjQuery = function(){
			jq.obj = null;
			_this.jQuery = null;
			jq.shadow = null;
			jq.sd_top = null;
			jq.sd_top_l = null;
			jq.sd_top_c = null;
			jq.sd_top_r = null;
			
			jq.sd_mid = null;
			jq.sd_mid_l = null;
			jq.sd_mid_c = null;
			jq.sd_mid_r = null;
			
			jq.sd_btm = null;
			jq.sd_btm_l = null;
			jq.sd_btm_c = null;
			jq.sd_btm_r = null;
			
			jq.border = null;
			jq.bd_top = null;
			jq.bd_top_l = null;
			jq.bd_top_c = null;
			jq.bd_top_r = null;
			
			jq.bd_mid = null;
			jq.bd_mid_l = null;
			jq.bd_mid_c = null;
			jq.bd_mid_r = null;
			
			jq.bd_btm = null;
			jq.bd_btm_l = null;
			jq.bd_btm_c = null;
			jq.bd_btm_r = null;
			
			jq.container = null;
			jq.ctn_top = null;
			jq.ctn_top_l = null;
			jq.ctn_top_c = null;
			jq.ctn_top_r = null;
			
			jq.ctn_mid = null;
			jq.ctn_mid_l = null;
			jq.ctn_mid_c = null;
			jq.ctn_mid_r = null;
			
			jq.ctn_btm = null;
			jq.ctn_btm_l = null;
			jq.ctn_btm_c = null;
			jq.ctn_btm_r = null;
			
			jq.btns = null;
			jq.btn_close = null;
			jq.btn_max = null;
			jq.btn_re = null;
			jq.btn_min = null;
			jq.btnsi = null;
			jq.btn_iclose = null;
			jq.btn_imax = null;
			jq.btn_ire = null;
			jq.btn_imin = null;
			
			jq.shadow_width = null;
			jq.title = null;
		};
		
		/**
		 * 初始化按钮事件
		 */
		var initButtonEvent = function(){
			var buttonArray = ["close","max","re","min"];
			for(i in buttonArray){
				var cur = buttonArray[i];
				eval("jq.btn_i"+cur+".unbind('mouseover').mouseover(function(){"+
					"	jq.btn_"+cur+".addClass('"+cur+"_hover');"+
					"}).unbind('mouseout').mouseout(function(){"+
					"	jq.btn_"+cur+".removeClass('"+cur+"_hover').removeClass('"+cur+"_pressed');"+
					"}).unbind('mousedown').mousedown(function(){"+
					"	jq.btn_"+cur+".addClass('"+cur+"_pressed');"+
					"}).unbind('mouseup').mouseup(function(){"+
					"	jq.btn_"+cur+".removeClass('"+cur+"_pressed');"+
					"});");
			}
			jq.btn_imin.click(function(){
				_this.min();
			});
			jq.btn_imax.click(function(){
				_this.max();
			});
			jq.btn_ire.click(function(){
				_this.re();
			});
			jq.btn_iclose.click(function(){
				_this.destroy();
			});
		};
		
		/**
		 * 初始化拖动事件
		 */
		var initDraggable = function(){
			jq.obj.draggable({
				addClasses: false,
				scroll : false,
				iframeFix : true,
				handle : jq.title,
				stop:function(){
					var dom = jq.obj.get(0);
					var top = dom.offsetTop;
					var left = dom.offsetLeft;
					_this.top(top);
					_this.left(left);
				}
			});
		};
		
		/**
		 * 初始化重置大小
		 */
		var initResizable = function(){
			jq.obj.resizable({
				addClasses: false,
				helper: "ui-resizable-helper",
				handles : "all",
				minHeight : config.minHeight,
				minWidth : config.minWidth,
				stop : function(){
					_this.width(jq.obj.width());
					_this.height(jq.obj.height());
				}
			});
		};
	};
	_.Window = Window;
	
	/**
	 * 获取最高的窗口
	 */
	_.Window.getTop = function(_container){
		var container = $(_container);
		return _( container.children("[class~='jdmer_window'][ontop='true']") );
	};
	_.Window.getUnderTop = function(_container){
		var container = $(_container);
		var win = _( container.children("[class~='jdmer_window'][ontop='true']") );
		if(win){
			var z = win.zindex();
			var unwin = _( container.children("[class~='jdmer_window'][jdmer_win_zindex='"+ ( Number(z) - 1) +"']") );
			return unwin;
		}
		return undefined;
	};
	
	_.window = function(_config){
		return new _.Window(_config);
	};
	
})(jDreamer,jQuery);